package com.ruoyi.cbs.black.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cbs.black.domain.BlackRecord;
import com.ruoyi.cbs.black.service.IBlackRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拉黑记录Controller
 * 
 * @author ruoyi
 * @date 2025-11-15
 */
@RestController
@RequestMapping("/black/record")
public class BlackRecordController extends BaseController
{
    @Autowired
    private IBlackRecordService blackRecordService;

    /**
     * 查询拉黑记录列表
     */
    @PreAuthorize("@ss.hasPermi('black:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlackRecord blackRecord)
    {
        startPage();
        List<BlackRecord> list = blackRecordService.selectBlackRecordList(blackRecord);
        return getDataTable(list);
    }

    /**
     * 导出拉黑记录列表
     */
    @PreAuthorize("@ss.hasPermi('black:record:export')")
    @Log(title = "拉黑记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlackRecord blackRecord)
    {
        List<BlackRecord> list = blackRecordService.selectBlackRecordList(blackRecord);
        ExcelUtil<BlackRecord> util = new ExcelUtil<BlackRecord>(BlackRecord.class);
        util.exportExcel(response, list, "拉黑记录数据");
    }

    /**
     * 获取拉黑记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('black:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blackRecordService.selectBlackRecordById(id));
    }

    /**
     * 新增拉黑记录
     */
    @PreAuthorize("@ss.hasPermi('black:record:add')")
    @Log(title = "拉黑记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlackRecord blackRecord)
    {
        return toAjax(blackRecordService.insertBlackRecord(blackRecord));
    }

    /**
     * 修改拉黑记录
     */
    @PreAuthorize("@ss.hasPermi('black:record:edit')")
    @Log(title = "拉黑记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlackRecord blackRecord)
    {
        return toAjax(blackRecordService.updateBlackRecord(blackRecord));
    }

    /**
     * 删除拉黑记录
     */
    @PreAuthorize("@ss.hasPermi('black:record:remove')")
    @Log(title = "拉黑记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blackRecordService.deleteBlackRecordByIds(ids));
    }
}
